﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TPDF
{
    public class TPdfDocument
    {
        IntPtr pdfIntPtr = IntPtr.Zero;
        private TPage _firstPage;
        private List<TPage> _pages = new List<TPage>();

        public TPdfDocument(string filePath, string password = "")
        {
            if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(filePath));
            if (!TpdfHelper.IsLoaded)
                TpdfHelper.Init();
            pdfIntPtr = TpdfHelper.LoadDocument(filePath, password);
            if (pdfIntPtr == IntPtr.Zero)
                throw new Exception("打开pdf出错!");
            PageCount = TpdfHelper.GetPageCount(pdfIntPtr);
            for (int i = 0; i < PageCount; i++)
            {
                _pages.Add(new TPage(pdfIntPtr, i));
            }
            _firstPage = new TPage(pdfIntPtr, 0);
        }
        public TPage FirstPage
        {
            get
            {
                return _firstPage;
            }
        }

        public List<TPage> Pages
        {
            get
            {

                return _pages;
            }
        }
        /// <summary>
        /// 页数
        /// </summary>
        public int PageCount { get; set; }

    }
}
